<template>
    <div class="objectCom">
        <div class="title">
            藏品基本信息
        </div>
        <div class="content">
            <el-table :data="tableData" style="width: 100%">
                <el-table-column align="center" prop="storeroom_name" label="测量墓室" width="120">
                </el-table-column>
                <el-table-column align="center" prop="content" label="笔记">
                </el-table-column>
                <el-table-column align="center" prop="result" label="研究成果">
                </el-table-column>
                <el-table-column align="center" prop="create_time" label="测量时间">
                </el-table-column>
                <el-table-column align="center" prop="is_show" label="显示">
                    <template slot-scope="scope">
                        <el-switch v-model="scope.row.is_show" @change="change(scope.row)" active-color="#A2754C"
                            inactive-color="#F7ECDC">
                        </el-switch>
                    </template>
                </el-table-column>
                <el-table-column align="center" fixed="right" label="操作" width="120">
                    <template slot-scope="scope">
                        <el-button size="mini" @click="delClick(scope.row)"><img
                                src="@/assets/image/del.png" />删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination @current-change="handleCurrentChange" :current-page="params.page" :page-size="params.page_size"
                layout="total, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>
    </div>
</template>

<script>
import { lists, edit, del, isShow } from '@/api/object_list'
export default {
    data() {
        return {
            params: {
                page: 1,
                page_size: 10
            },
            total: 0,
            tableData: []
        }
    },
    created() {
        this.lists()
    },
    methods: {
        lists() {
            lists(this.params).then(res => {
                console.log(res);
                this.total = res.data.count
                this.tableData = res.data.lists
                this.tableData.forEach(item => {
                    item.is_show = item.is_show == 1?true:false
                })
            }).catch(e => {
                console.log(e);
            })
        },
        change(val) {
            console.log(val);
            let data = {
                id: val.id,
                is_show: val.is_show
            }
            isShow(data).then(res => {
                console.log(res);
                if (res.status == 1) {
                    this.params.page = 1
                    this.lists()
                } else {
                    this.$message.error(res.info);
                }
            })
        },
        delClick(val) {
            this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                del({ id: val.id}).then(res => {
                    console.log(res);
                    if (res.status == 1) {
                        this.params.page = 1
                        this.lists()
                        this.$message({
                            type: 'success',
                            message: res.info
                        });
                    } else {
                        this.$message.error(res.info);
                    }
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        handleCurrentChange(val) {
            this.params.page = val
            this.lists()
        }
    }
}
</script>

<style lang="scss" scoped>
.objectCom {
    width: 1000px;
    margin: 0 auto;
    padding: 10px 0;

    .title {
        font-size: 24px;
        font-family: PingFang SC, PingFang SC;
        font-weight: 600;
        color: #683C19;
        text-align: left;
        margin: 10px 0;
    }

    .content {
        padding: 10px;
        background: #fff;
        border-radius: 18px;

        ::v-deep .el-button {
            span {
                display: flex;
                align-items: center;

                img {
                    margin-right: 10px;
                }
            }
        }
    }
}
</style>